package com.company.ems.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class CreateDatabaseUtil {
    
    private static final String URL = "jdbc:mysql://159.75.137.11:3306?useSSL=false&serverTimezone=UTC&characterEncoding=utf8";
    private static final String USERNAME = "admin";
    private static final String PASSWORD = "soft2025";
    
    public static void main(String[] args) {
        System.out.println("开始创建作业数据库...");
        
        Connection conn = null;
        PreparedStatement pstmt = null;
        
        try {
            // 连接到MySQL服务器（不指定数据库）
            conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
            
            // 创建数据库
            String createDatabase = "CREATE DATABASE IF NOT EXISTS ems_assignment " +
                    "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
            
            pstmt = conn.prepareStatement(createDatabase);
            pstmt.executeUpdate();
            System.out.println("✓ 数据库 'ems_assignment' 创建成功");
            
        } catch (SQLException e) {
            System.err.println("✗ 数据库创建失败: " + e.getMessage());
            e.printStackTrace();
        } finally {
            try {
                if (pstmt != null) pstmt.close();
                if (conn != null) conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}